home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
FONT_SIZ.C
< prev
next >
Wrap
Text File
|
1989-02-09
|
10KB
|
391 lines
/************************************************************************
font_size_stylemenu.c
For LightspeedC 2.15
Apple Macintosh System Version 6.0
07/04/88
GALEN B. BABCOCK
1932 N. TURQUOISE
WICHITA, KANSAS 67212
316-721-1226
GEnie: G.BABCOCK
CompuServe: 74666,2457
Font, Size, and Style menu utilities
CONTAINS
------------------------------------------------------
outline_real_fonts()
check_style_menu()
check_font_name()
check_font_size()
select_style_menu()
select_size_menu()
select_font_menu()
------------------------------------------------------
---- Revisions ----
AUTHOR DESCRIPTION
------ ----------------------------------------------------
************************************************************************/
#include <QuickDraw.h>
#include <MenuMgr.h>
#define PlainItem 1
#define BoldItem 2
#define ItalicItem 3
#define UnderlineItem 4
#define OutlineItem 5
#define ShadowItem 6
#define CondenseItem 7
#define ExtendItem 8
/************************************************************************
The font_size_stylemenu.c routines expect the Style menu to be
set up in the following order...
Plain
Bold
Italic
Underline
Outline
Shadow
Condense
Extend
For routines which accept a "begin" and "length" parameters (int),
it is assumed that the related menu items start at the "begin"-th item
in the menu, and continue for "length" number of items. For example,
the following menu of font sizes and styles are contained in the
same menu. To use font size routines, you would pass "1" in the "begin"
parameter, and "7" in the "length" parameter, and for routines that
deal with font styles, pass "9" as the "begin" parameter, and "8" as
the "length" parameter.
9 <- begin = 1
10
12
14
18
24
36 <- length = 7
------
Plain <- begin = 9
Bold
Italic
Underline
Outline
Shadow
Condense
Extend <- length = 8
************************************************************************/
/*
=========================================================================
[ ]
[ check_style_menu() ]
[ ]
[ Places check marks beside the menu item style descriptors which ]
[ are contained in the style passed in "theStyle" ]
[ ]
=========================================================================
*/
check_style_menu(theMenu,theStyle,begin,length)
MenuHandle theMenu; /* the Style Menu */
char theStyle; /* Style to reflect in menu */
int begin; /* location of "Plain" item */
int length; /* number of style items */
{
int limit;
int index;
int bitPos;
limit = begin+length-1;
if (theStyle == 0){
CheckItem(theMenu,begin,TRUE);
for (index=begin+1;index<=limit;index++)
CheckItem(theMenu,index,FALSE);
}
else{
CheckItem(theMenu,begin,FALSE);
/*
NOTE
===========================================================
Bit Pattern BitTst Menu
Style 0 1 2 3 4 5 6 7 Position Item
------------ --------------- -------- ----
bold = 1, 0 0 0 0 0 0 0 1 7 2
italic = 2, 0 0 0 0 0 0 1 0 6 3
underline = 4, 0 0 0 0 0 1 0 0 5 4
outline = 8, 0 0 0 0 1 0 0 0 4 5
shadow = 16, 0 0 0 1 0 0 0 0 3 6
condense = 32, 0 0 1 0 0 0 0 0 2 7
extend = 64 0 1 0 0 0 0 0 0 1 8
===========================================================
Since the Styles are bit positions, we can cycle through
testing each bit position, which correlates to a Style
being enabled or disabled.
In this routine, we start with the lease significant bit,
0 1 2 3 4 5 6 7
---
which corresponds to the Bold style, or the 2nd item in
the style menu, then proceed to the 6th bit, 3rd item,
7th bit, 4th item, etc.
For each bit position, we can calculate the menu item,
relative to the "begin" menu item, using:
menuitem = begin + 8 - bitPos
*/
for (index=begin,bitPos=7;index<limit;index++,bitPos--){
if (BitTst(&theStyle,bitPos) == TRUE)
CheckItem(theMenu,begin+8-bitPos,TRUE);
else
CheckItem(theMenu,begin+8-bitPos,FALSE);
}
}
}
/*
=========================================================================
[ ]
[ select_style_menu() ]
[ ]
[ Changes theStyle (char *) according to theItem selected from the ]
[ Style menu. If condense is selected, extend is deselected, ]
[ and vice versa, since having both selected simultaneously makes ]
[ no sense. ]
[ ]
=========================================================================
*/
select_style_menu(theMenu,theItem,begin,length,theStyle)
MenuHandle theMenu; /* the style menu */
int theItem; /* item selected from the menu */
int begin; /* menu item of the "Plain" style item */
int length; /* number of style items */
char *theStyle; /* the style to change */
{
switch (theItem-begin+1){
case PlainItem: *theStyle = 0;
break;
case BoldItem: *theStyle ^= bold;
break;
case ItalicItem: *theStyle ^= italic;
break;
case UnderlineItem: *theStyle ^= underline;
break;
case OutlineItem: *theStyle ^= outline;
break;
case ShadowItem: *theStyle ^= shadow;
break;
case CondenseItem: *theStyle ^= condense;
*theStyle &= (0XFF-extend);
break;
case ExtendItem: *theStyle ^= extend;
*theStyle &= (0XFF-condense);
break;
default: break;
}
}
/*
=========================================================================
[ ]
[ outline_real_fonts() ]
[ ]
[ Given the font number in theFont, this function outlines the ]
[ font sizes in the font size menu for which there is a defined ]
[ font resource for that size. All font sizes which have to be ]
[ scaled are drawn in plain style. ]
[ ]
=========================================================================
*/
outline_real_fonts(theMenu,begin,length,theFont)
MenuHandle theMenu; /* font size menu */
int begin; /* first font size item */
int length; /* number of font size items */
int theFont; /* which font */
{
int limit;
int index;
Str255 mString;
long mNum;
limit = begin+length-1;
for(index=begin;index<=limit;index++){
GetItem(theMenu,index,mString);
StringToNum(mString,&mNum);
if (RealFont(theFont,(int)mNum))
SetItemStyle(theMenu,index,outline);
else
SetItemStyle(theMenu,index,0);
}
}
/*
=========================================================================
[ ]
[ check_font_name() ]
[ ]
[ For the font in "theFont", finds the name of the font in the ]
[ Font menu "theMenu", and places a check mark beside it, and ]
[ removes check marks from all other menu items. ]
[ ]
=========================================================================
*/
check_font_name(theMenu,theFont)
MenuHandle theMenu; /* Font Menu */
int theFont; /* font number to check mark */
{
int index,limit;
Str255 fStr,mStr;
GetFontName(theFont,fStr);
PtoCstr((char *)fStr);
limit = CountMItems(theMenu);
for(index=1;index<=limit;index++){
GetItem(theMenu,index,mStr);
PtoCstr((char *)mStr);
if (strcmp(mStr,fStr) == 0)
CheckItem(theMenu,index,TRUE);
else
CheckItem(theMenu,index,FALSE);
}
}
/*
=========================================================================
[ ]
[ check_font_size() ]
[ ]
[ Places a checkmark beside the font size menu item passed in ]
[ "theSize", removes check marks from all other menu items. ]
[ ]
=========================================================================
*/
check_font_size(theMenu,begin,length,theSize)
MenuHandle theMenu; /* font Size menu */
int begin; /* first Size item in the menu */
int length; /* number of Size items */
int theSize; /* the size to check mark */
{
int index;
int limit;
Str255 mStr;
long mVal;
limit = begin+length-1;
for(index=begin;index<=limit;index++){
GetItem(theMenu,index,mStr);
StringToNum(mStr,&mVal);
if ((int)mVal == theSize)
CheckItem(theMenu,index,TRUE);
else
CheckItem(theMenu,index,FALSE);
}
}
/*
=========================================================================
[ ]
[ select_size_menu() ]
[ ]
[ Changes the text font size "theSize" (int *) to the size selected ]
[ from "theMenu" font size menu. Places a checkmark beside the size ]
[ selected, and removes checks from all other items ]
[ ]
=========================================================================
*/
select_size_menu(theMenu,theItem,begin,length,theSize)
MenuHandle theMenu; /* the font size menu */
int theItem; /* item selected */
int begin; /* first font size item */
int length; /* number of font size items */
int *theSize; /* change to font selected font size */
{
int limit;
int index;
Str255 mStr;
long mVal;
limit = begin+length-1;
for(index=begin;index<=limit;index++)
CheckItem(theMenu,index,FALSE);
CheckItem(theMenu,theItem,TRUE);
GetItem(theMenu,theItem,mStr);
StringToNum(mStr,&mVal);
*theSize = (int)mVal;
}
/*
=========================================================================
[ ]
[ select_font_menu() ]
[ ]
[ Changes the text font "theFont" (int *) to the font selected ]
[ from "theMenu" font menu. Places a checkmark beside the font ]
[ selected, and removes checks from all other items. ]
[ ]
=========================================================================
*/
select_font_menu(theMenu,theItem,theFont)
MenuHandle theMenu; /* Font menu */
int theItem; /* item selected */
int *theFont; /* place for the new font number */
{
Str255 fnName;
GetItem(theMenu,theItem,fnName);
GetFNum(fnName,theFont);
}